package fatworm.concept.datatype;
/**
 * data type FLOAT
 */
public class FatFloat extends fatworm.concept.DataType{
	private static final FatFloat instance = new FatFloat();
	public static FatFloat getInstance(){
		return instance;
	}
	
	private FatFloat(){}
	public int getTypeKey() {
		return T_FLOAT;
	}
	/**
	 * create a new float value 
	 */
	public FloatValue createValue( float value ){
		return new FloatValue( value );
	}
	
	public FloatValue convert( SqlValue value ) 
			throws ConvertException {
		switch( value.getType().getTypeKey() ){
			case T_INT:
				return createValue( (float) ((FatInt.IntValue)value).value ) ;
			case T_FLOAT:
				return (FloatValue) value;
			case T_STRING:
				try{
					return createValue( Float.parseFloat(value.toString()));
				}catch( java.lang.NumberFormatException e){
					throw new ConvertException( value , this );
				}
			default: throw new ConvertException( value , this );
		}
	}
	

	public String toString() {
		return "FLOAT";
	}
	public class FloatValue extends SqlValue{
		public float value;
		private FloatValue( float value ){
			this.value = value; 
		}

		public String toString() {
			return value+"";
		}
	}
}
